import React, { Component } from 'react'
import { Icon, Divider, Popconfirm, Input, Tooltip, Dropdown, Menu } from 'antd';

export default class TelGroupNode extends Component {
    constructor(props) {
        super(props);
        this.state = {
            telGroupName:''
        }
    }

    setTelGroupName = (e)=>{
        this.setState({
            telGroupName: e.target.value
        })
    }

    menu = (
        <Menu>
          <Menu.Item key="1" onClick = {()=>{
                const {tnode, addSendListFunc} = this.props
                addSendListFunc(
                    {
                        type: "group",
                        node: tnode
                    }
                )
              }}>添加此分组</Menu.Item>
        </Menu>
    );

    render() {
        const {name,glevel,id} = this.props.tnode
        const {nameKey, dispatch} = this.props
        let selName = name
        if(nameKey && nameKey!==''){
            let index = name.indexOf(nameKey)
            if(index !== -1){
                let nlength = nameKey.length
                let before = name.substr(0,index)
                let after = name.substr(index+nlength)
                selName = (<span>{before}<span style={{ color: '#f50' }}>{nameKey}</span>{after}</span>) 
            }
        }

        return (
            <div>
                <Dropdown overlay={this.menu} trigger={['contextMenu']}>
                <span onClick = {()=>{
                        const {tnode, dispatch, type} = this.props
                        let action = ''
                        if(type === "Personal"){
                            action = 'telBook/fetchSelTelBookByUserId'
                        }
                        if(type === "Enterprise"){
                            action = 'telBookEnterprise/fetchSelTelBookByEnterprise'
                        }
                        dispatch({
                            type: action,
                            payload: {
                                name: null,
                                phone: null,
                                page: 1,
                                groupId: tnode.id
                            }
                        })
                    }}>{selName}</span>
                </Dropdown>
            </div>
        )
    }
}
